﻿/* Write a program that extracts from given XML file all the text without the tags. Example:
<?xml version="1.0"><student><name>Pesho</name>
 * <age>21</age><interests count="3"><interest>
 * Games</instrest><interest>C#</instrest><interest>
 * Java</instrest></instrest></student>
 */
using System;
using System.IO;
using System.Text.RegularExpressions;

namespace _10.ExtractXML
{
    class ExtractXML
    {
        static void Main()
        {
            Console.Write("Path to XML file: ");
            string path_to_input_file = Console.ReadLine();
            string xmlFileContents; 
            try
            {
                StreamReader SR = new StreamReader(@path_to_input_file);
                using (SR)
                {
                    xmlFileContents = SR.ReadToEnd();
                }
            }
            catch (FileNotFoundException fn)
            {
                throw new FileNotFoundException("File not found, " + fn.Message);
            }
            catch (OverflowException oe)
            {
                throw new OverflowException("Stack overflow, may be the file is too big?, " + oe.Message);
            }
            catch (IOException ioe)
            {
                throw new IOException("Error: the input file could not be read, " + ioe.Message);
            }
            Regex r = new Regex(@"<(.*?)>");
            string result = r.Replace(xmlFileContents, "");
           
            Console.WriteLine(result.Trim());

        }
    }
}
